import { ipcMain } from "electron";
// import * as testWin from './testwindowdll'


let plateform:any;

export const initIpcDemo = (data:string) => {
  // 判断平台
  if(data.includes('win')){
    plateform=testWin
  }else if(data.includes('linux')){
    console.log('the plateform is ',data)
  }
  
  // 同步处理通信，并等待主进程返回值
  ipcMain.on("event-on-test", (e, data: string) => {
    console.log("同步处理通信，并等待主进程返回值")
    setTimeout(() => {
      e.returnValue = "主进程同步响应：  " + data;
    }, 1000);
  });

  // 异步处理通信，异步返回结果
  ipcMain.handle("event-handle-test", (e, data: string) => {
    return "主进程异步响应:" + data;
  });

  // 异步处理一次
  ipcMain.handleOnce("event-handleOnce-test", (e) => {
    console.log("异步通信处理一次！");
  });

  // 双向通信处理
  ipcMain.handle("event-handle-togeter-test", (e, data: string) => {
    e.sender.send("event-handle-togeter-test", "主进程通知" + data);
  });
     // 在控制台可以看到
  ipcMain.on('openFlyCar',()=>{
    console.log('收到')
  })
  ipcMain.on('message',(_,num)=>{
    console.log(num,'来了')
  })
  ipcMain.handle("sum", (e, a:number,b:number) => {

  //    let sum=plateform.myAdd(1,2);
  //    let maxNum = plateform.myMax(1,2);
  //  return sum;
  });
};